home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / TagFile / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  6KB  |  261 lines

  1. // skeleton code for writing a new door
  2.  
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <dos/dos.h>
  6. #include <clib/exec_protos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <ctype.h>
  14. #include <time.h>
  15.  
  16.  
  17. #ifdef __SASC
  18. int CXBRK(void) { return(0); }
  19. int _CXBRK(void) { return(0); }
  20. void chkabort(void) {}
  21. #endif
  22.  
  23. #include <HBBS/ANSI_Codes.h>
  24. #include <HBBS/Defines.h>
  25. #include <HBBS/types.h>
  26. #include <HBBS/structures.h>
  27. #include <HBBS/hbbscommon_protos.h>
  28. #include <HBBS/hbbscommon_pragmas.h>
  29. #include <HBBS/Hbbsnode_protos.h>
  30. #include <HBBS/Hbbsnode_pragmas.h>
  31. #include <HBBS/release.h>
  32. char *versionstr="$VER: TagFile "RELEASE_STR;
  33.  
  34. struct Library *HBBSCommonBase=NULL;
  35. struct Library *HBBSNodeBase=NULL;
  36.  
  37. struct BBSGlobalData *BBSGlobal=NULL;
  38. struct NodeData *N_ND=NULL;
  39. int N_NodeNum=-1;
  40. char outstr[1024]; // temp string for displaying text..
  41.  
  42. static VOID cleanup(ULONG num)
  43. {
  44.   if (HBBSNodeBase)
  45.   {
  46.     HBBS_CleanUpDoor();
  47.     CloseLibrary (HBBSNodeBase);
  48.   }
  49.  
  50.   if (HBBSCommonBase)
  51.   {
  52.     HBBS_CleanUpCommon();
  53.     CloseLibrary (HBBSCommonBase);
  54.   }
  55.  
  56.   if (num) printf("Door Error = %d\n",num);
  57.  
  58.   exit(0);
  59. }
  60.  
  61. static VOID init(char *name)
  62. {
  63.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  64.   {
  65.     cleanup(1);
  66.   }
  67.  
  68.   if (!(HBBS_InitCommon()))
  69.   {
  70.     cleanup(2);
  71.   }
  72.  
  73.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  74.   {
  75.     cleanup(3);
  76.   }
  77.  
  78.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  79.   {
  80.     cleanup(4);
  81.   }
  82.   SetProgramName(name);
  83. }
  84.  
  85. V_BOOL HBBS_FindConfFile(V_BIGNUM ConfNum,char *filename,char *fullname)
  86. {
  87.   // searches the download paths of the conf for the filename specified
  88.   // and returns TRUE if the file is found.  The full path and filename
  89.   // are then stored in fullname if fullname is not a null pointer
  90.  
  91.   V_BOOL retval=FALSE;
  92.   struct ConfData *Conf;
  93.   char tmpstr[1024];
  94.   struct Node *node;
  95.  
  96.  
  97.   // valid conf num ?
  98.   if (ConfNum>=1 && ConfNum<=BBSGlobal->Conferences)
  99.   {
  100.     Conf=(struct ConfData *)GetNode(BBSGlobal->ConfList,ConfNum-1);
  101.  
  102.     // any download paths to search ??
  103.     if (Conf->Download)
  104.     {
  105.       for (node=Conf->Download->lh_Head;!retval && node->ln_Succ;node=node->ln_Succ)
  106.       {
  107.         strcpy(tmpstr,node->ln_Name);
  108.         strcat(tmpstr,filename);
  109.         if (PathOK(tmpstr))
  110.         {
  111.           retval=TRUE;
  112.           if (fullname)
  113.           {
  114.             strcpy(fullname,tmpstr);
  115.           }
  116.         }
  117.       }
  118.     }
  119.   }
  120.   return(retval);
  121.  
  122. }
  123.  
  124. V_BIGNUM GetFileSize(char *filename)
  125. {
  126.   BPTR FL;
  127.   struct FileInfoBlock FB;
  128.   V_BIGNUM retval=0;
  129.  
  130.   if (filename)
  131.   {
  132.     if (FL=Lock(filename,ACCESS_READ))
  133.     {
  134.       if (Examine(FL,&FB))
  135.       {
  136.         retval=FB.fib_Size;
  137.       }
  138.       UnLock(FL);
  139.     }
  140.   }
  141.   return(retval);
  142. }
  143.  
  144. BOOL AlreadyTagged(UBYTE *fullname)
  145. {
  146.   struct Node *node;
  147.   BOOL Found=FALSE;
  148.  
  149.   for (node=N_ND->TaggedFileList->lh_Head;!Found && node->ln_Succ;node=node->ln_Succ)
  150.   {
  151.     Found = (stricmp(fullname,node->ln_Name)==0);
  152.   }
  153.   return(Found);
  154. }
  155.  
  156. void TagPrompt( void )
  157. {
  158.   DOOR_WriteText(ANSI_FG_YELLOW "Tagging "ANSI_FG_BLUE"> "ANSI_FG_WHITE);
  159. }
  160.  
  161. void DoorMain(int argc,char *argv[])
  162. {
  163.   short loop;
  164.   struct TaggedFile *filetagnode;
  165.   char filename[1024],fullname[1024];
  166.   V_BIGNUM ConfNum;
  167.   BOOL FileOK;
  168.  
  169.   V_BIGNUM tagged=0;
  170.  
  171. //  DOOR_WriteText("\r\n-=[  Hydra AddTag V1.0  ]=- ============ -=[  (C) 1995 Deluxe Software Ltd  ]=-\r\n");
  172.  
  173.  
  174.   for(loop=2;loop<argc;loop++)
  175.   {
  176.     if (loop==2) TagPrompt();
  177.  
  178.     if (sscanf(argv[loop],"C=%ld,N=%s",&ConfNum,filename)==2)
  179.     {
  180.       RemoveSpaces(filename);
  181.       DOOR_WriteText(filename);
  182.  
  183.       FileOK=FALSE;
  184.  
  185.  
  186.       // check existence of file.
  187.       if (ConfNum>0)
  188.       {
  189.         if (HBBS_FindConfFile(ConfNum,filename,fullname))
  190.         {
  191.           FileOK=TRUE;
  192.         }
  193.       }
  194.       else
  195.       {
  196.         if (PathOK(filename))
  197.         {
  198.           FileOK=TRUE;
  199.           strcpy(fullname,filename);
  200.         }
  201.       }
  202.  
  203.       if (FileOK)
  204.       {
  205.         if (AlreadyTagged(fullname))
  206.         {
  207.           DOOR_WriteText(ANSI_FG_BLUE" - "ANSI_FG_CYAN"File Already Tagged!\r\n"ANSI_FG_WHITE);
  208.           if (loop<argc-1) TagPrompt();
  209.         }
  210.         else
  211.         {
  212.           if (filetagnode=AllocVec(sizeof(struct TaggedFile),MEMF_PUBLIC|MEMF_CLEAR))
  213.           {
  214.             filetagnode->node.ln_Name=DupStr(fullname);
  215.  
  216.             if (ConfNum>0) filetagnode->WarezFile=TRUE; else filetagnode->WarezFile=FALSE;
  217.             filetagnode->ConferenceNum=ConfNum;
  218.  
  219.  
  220.             filetagnode->FileSize=GetFileSize(fullname);
  221.  
  222.             AddTail(N_ND->TaggedFileList,(struct Node*) filetagnode);
  223.             N_ND->TaggedFiles++;
  224.             tagged++;
  225.  
  226.             if (loop<argc-1) DOOR_WriteText(ANSI_FG_BLUE","ANSI_FG_WHITE);
  227.  
  228.           }
  229.         }
  230.       }
  231.       else
  232.       {
  233.         DOOR_WriteText(ANSI_FG_BLUE" - "ANSI_FG_CYAN"File Not Found!\r\n"ANSI_FG_WHITE);
  234.         if (loop<argc-1) TagPrompt();
  235.       }
  236.     }
  237.   }
  238.   DOOR_WriteText("\r\n");
  239.   sprintf(filename,"%ld",tagged);
  240.   DOOR_Return(filename);
  241. }
  242.  
  243. int main(int argc,char *argv[])
  244. {
  245.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  246.   {
  247.     printf("Invalid/No Paramaters for door!\n");
  248.     exit (20);
  249.   }
  250.   init("TAG_FILE");
  251.  
  252.   if (BBSGlobal=HBBS_GimmeBBS())
  253.   {
  254.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  255.     {
  256.       DoorMain(argc,argv);
  257.     }
  258.   }
  259.   cleanup(0);
  260. }
  261.